package com.snail.jj.androiddemos.bases;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.snail.jj.androiddemos.R;

/**
 * Created by snail on 2017/4/10.
 */

public class FoundationWidgetsActivity extends BaseActivity {

    private ListView listView;
    private String[] dataSource = {
            "TextView",
            "ImageView",
            "ListView",
            "EditView"
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_foundation);
        initView();
    }

    public void initView() {
        setTitleBarTitle("基础控件");
        setRightViewVisiable(View.INVISIBLE);
        setTitleClick(true);
        listView = (ListView) findViewById(R.id.id_foundationWidgets_listView);
        ArrayAdapter<String> adapter =
                new ArrayAdapter<String>(FoundationWidgetsActivity.this,R.layout.support_simple_spinner_dropdown_item,dataSource);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(
                new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                        try {
                            String className = "com.snail.jj.androiddemos.foundationwidgets." + dataSource[position] + "Activity";
                            Class<?> clazz = Class.forName(className);
                            BaseActivity activity = (BaseActivity) clazz.newInstance();
                            Intent intent = new Intent(FoundationWidgetsActivity.this,activity.getClass());
                            startActivity(intent);
                        }catch (ClassNotFoundException e) {
                            e.printStackTrace();
                        }catch (IllegalAccessException e) {
                            e.printStackTrace();
                        }catch (InstantiationException e) {
                            e.printStackTrace();
                        }
                    }
                }
        );
    }

    @Override
    public void leftViewAction() {
        super.leftViewAction();
    }

    @Override
    public void rightViewAction() {
        super.rightViewAction();
    }


}
